import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

color = ["green", "lightgreen"]
sns.set_palette(color)

df=pd.read_csv('stata-replication/data/graphs.csv')

var = ["us_depend", "us_trust", "us_infl"]
i = 0
while i < 3:
    g =  sns.catplot(y=var[i], data=df, kind='count', hue='elec_tr', edgecolor=".6")
    g.set_axis_labels("Number of Respondents", "")
    g.set_yticklabels(["strongly\ndisagree" , "disagree" , "neither" , "agree" , "strongly\nagree"])
    g.set_yticklabels(rotation=20) 
    g._legend.set_title('Experimental Group')
    new_labels = ['Control', 'Treatment']
    for t, l in zip(g._legend.texts, new_labels):
        t.set_text(l)
    sns.move_legend(g, "upper right")
    plt.tight_layout()
    plt.savefig(f'stata-replication/figures/{var[i]}.svg')
    i = i + 1

i = 0
while i < 3:
    g =  sns.catplot(x=var[i], data=df, kind='count', hue='elec_tr', col="ldp_s",  edgecolor=".6")
    titles = ['LDP Opposition','Nuetral','LDP Suppporter']
    for ax,title in zip(g.axes.flatten(),titles):
        ax.set_title(title )
    g._legend.set_title('Experimental Group')
    new_labels = ['Control', 'Treatment']
    for t, l in zip(g._legend.texts, new_labels):
        t.set_text(l)
    
    g.set_axis_labels("", "Number of Respondents")
    g.set_xticklabels(["strongly\ndisagree" , "disagree" , "neither" , "agree" , "strongly\nagree"])
    g.set_xticklabels(rotation=20) 
    plt.savefig(f'stata-replication/figures/ldp_{var[i]}.svg')
    i = i + 1

f = open("graphs.txt", "w")
f.write("Graphs generated by python")
f.close()
exit


